use std::fmt::{Display, Formatter,Result};
fn main() {
    const X:u32 = 3+4;
    let x:uew = 4+3;
    /*
    
    let an = (42,).0;
    println!("{:}",an);
    //const AN:i32 = an;
    //const An:i32 = (42,).0;

    for i in 1..102{
        if i%15==0 {
            println!("FizzBuzz")
        }else if i%3==0 {
            println!("Fizz")            
        } else if i%5==0 {
            println!("Buzz")
        }else {
            println!("{}",i)
            
        }
    }
    println!("+++++++++++++++++++================");
    for i in 1..102{
        match (i%3,i%5) {
            (0,0) =>println!("FizzBuzz"),
            (0,_) =>println!("Fizz"),
            (_,0) =>println!("Buzz"),
            (_,_) =>println!("{}",&i),
        }
    } */
}
/*
fn main1() {
    println!("类型系统");
    println!("泛型：是运行时指定数据类型的机制，可以编写更为抽象和通用的代码，减少重复的工作量，即一套代码就可以应用于多种类型。");
    struct Rectangle1<T> {
        width: T,
        height: T,
    }
    struct Rectangle2<T, U> {
        width: T,
        height: U,
    }
    impl<T> Rectangle1<T> {
        fn width(&self) -> &T {
            &self.width
        }
        fn height(&self) -> &T {
            &self.height
        }
    }
    impl Rectangle1<i32> {
        fn area(&self) -> i32 {
            self.width * self.height
        }
    }
    impl<T, U> Rectangle2<T, U> {
        fn width(&self) -> &T {
            &self.width
        }
        fn height(&self) -> &U {
            &self.height
        }
    }
    // let r = Rectangle1{width:8,height:2.2};
    let r = Rectangle1 { width: 8, height: 2 };
    println!("{},{},{},{},{}", r.width, r.height, r.width(), r.height(), r.area());
    let r = Rectangle2 { width: 8, height: 2.25 };
    println!("{},{},{},{}", r.width, r.height, r.width(), r.height());

    println!("trait系统");
    trait Geometry {
        fn area(&self) -> f32;
        fn perimeter(&self) -> f32;
    }
    struct Rectangle {
        width: f32,
        height: f32,
    }
    impl Geometry for Rectangle {
        fn area(&self) -> f32 {
            self.width * self.height
        }
        fn perimeter(&self) -> f32 {
            (self.width + self.height) * 2.0
        }
    }
    struct Circle {
        radius: f32,
    }
    impl Geometry for Circle {
        fn area(&self) -> f32 {
            3.14 * self.radius * self.radius
        }
        fn perimeter(&self) -> f32 {
            3.14 * 2.0 * self.radius
        }
    }
    let r = Circle { radius: 8.8 };
    println!("{},{}", r.area(), r.perimeter());


    println!("trait 作为参数");
    println!("impl Trait:");
    fn print(g: impl Geometry) {
        println!("area:{},p{}", g.area(), g.perimeter())
    }

    print(r);
    println!("");
    impl Display for Rectangle {
        fn fmt(&self, f: &mut Formatter<'_>) -> Result {
            write!(f, "Rectangle:({},{})", self.width, self.height)
        }
    }

    println!("输出格式化内容 impl Geometry + Display");
    println!("use std::fmt::{{Display, Formatter,Result}};");
    fn print2(g: impl Geometry + Display){
        println!("{},area:{},g:{}",g,g.area(),g);
    }
    let r = Rectangle{width:10.5,height:5.5};
    print2(r);
    fn area_add(g1:impl Geometry,g2:impl Geometry){
        println!("{},{},{}",g1.area(),g2.area(),g1.area()+g2.area());
    }
    let r2 = Rectangle{width:5.0,height:6.5};
    let c = Circle{radius:5.0};
    area_add(c,r2);

    println!("");
    println!("");
    println!("");
    println!("");
    println!("");
    println!("");
    println!("");
    println!("");
    println!("");
    println!("");
    println!("");
    println!("");
    println!("");
    println!("");
    println!("");
}

macro_rules! create_function {
    // This macro takes an argument of designator `ident` and
    // creates a function named `$func_name`.
    // The `ident` designator is used for variable/function names.
    ($func_name:ident) => {
        fn $func_name() {
            // The `stringify!` macro converts an `ident` into a string.
            println!("You called {:?}()",
                     stringify!($func_name));
        }
    };
}

// 使用上述宏创建名为 `foo` 和 `bar` 的函数。
create_function!(foo);
create_function!(bar);

macro_rules! print_result {
    // 这个宏接受一个 `expr` 类型的表达式并将其作为字符串连同其结果一起打印出来。
    // `expr` 指示符用于表达式。
    ($expression:expr) => {
        // `stringify!` 将表达式原样转换为字符串。
        println!("{:?} = {:?}",
                 stringify!($expression),
                 $expression);
    };
}

fn main30() {
    foo();
    bar();

    print_result!(1u32 + 1);

    // 回想一下，块也是表达式！
    print_result!({
        let x = 1u32;

        x * x + 2 * x - 1
    });
} */
